import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core';

@Component({
  selector: 'app-external-control',
  templateUrl: './external-control.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ExternalControlComponent {
  status = true;
  loading = false;

  constructor(private cdr: ChangeDetectorRef) {}

  switchChange() {
    if (this.loading) return;

    if (this.status) {
      this.loading = true;
      const timeOut = setTimeout(() => {
        clearTimeout(timeOut);
        this.loading = false;
        this.status = false;
        this.cdr.markForCheck();
      }, 1000);
    } else {
      this.status = true;
    }

    this.cdr.markForCheck();
  }
}
